use std::cell::Cell;

use thunderdome::Index;

use super::message::ObjectType;

#[derive(Debug)]
pub struct EditorActions {
    pub obj_type: Cell<ObjectType>,
    pub target: Cell<Option<Index>>,
}

impl EditorActions {
    pub fn new() -> Self {
        Self {
            obj_type: Cell::new(ObjectType::GameObject),
            target: Cell::new(None),
        }
    }

    pub fn select(&self, index: Option<Index>) {
        self.target.set(index);
    }

    pub fn unselect(&self) {
        self.target.set(None);
    }

    pub fn current(&self) -> (ObjectType, Option<Index>) {
        (self.obj_type.get(), self.target.get())
    }

    pub fn select_with_type(&self, obj_type: ObjectType, index: Option<Index>) {
        self.obj_type.set(obj_type);
        self.target.set(index);
    }

    pub fn get_type(&self) -> ObjectType {
        self.obj_type.get()
    }

    pub fn set_type(&self, obj_type: ObjectType) {
        self.obj_type.set(obj_type);
        self.target.set(None);
    }

    pub fn get_current_game_object(&self) -> Option<Index> {
        match self.obj_type.get() {
            ObjectType::GameObject => self.target.get(),
            _ => None,
        }
    }

    pub fn get_current_ui_node(&self) -> Option<Index> {
        match self.obj_type.get() {
            ObjectType::UiObject => self.target.get(),
            _ => None,
        }
    }
}
